package CutLoad.components
{
	import CutLoad.Base;
	/**
	 * 单选框 
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 
	 */	
	public class CRadioButton extends CCheckBox
	{
		override public function init(arrLabel:Array, funClick:Function=null, spaceX:Number=5, itemSpaceX:Number=5):void{
			super.init(arrLabel,funClick,spaceX,itemSpaceX);
			this.value=[0,true]
		}
		override protected function addOneItem(strLabel:String):CCheckBoxItem{
			var item:CCheckBoxItem=new CCheckBoxItem();
			item.setSkin(Skin.getInstance().getSkin(7)[0],Skin.getInstance().getSkin(7)[1])
			item.init(strLabel,itemSpaceX,funItemClick);
			arr.add(item);
			return item;
		}
		override protected function funItemClick(itemTem:CCheckBoxItem):void{
			for(var i:Number=0;i<arr.length;i++){
				var itemtem:CCheckBoxItem=arr.data[i];
				if(arr.data[i]==itemTem){
					itemtem.value=true
					if(funClick!=null) funClick(i,itemTem);
				}else{
					itemtem.value=false;
				}
			}
		}
		/**
		 * 设置选重或不选重
		 * @param arrSelect 格式：[第几个元素(从0开始),选重true或不选重false]
		 * 
		 */		
		override public function set value(arrSelect:Array):void{
			if(arrSelect.length!=2) throw new Error("该数组只要需要两个元素:[第几个元素(从0开始),选重true或不选重false]");
			for(var i:Number=0;i<arr.length;i++){
				var itemtem:CCheckBoxItem=arr.data[i];
				itemtem.value=false;
			}
			arr.data[arrSelect[0]].value=arrSelect[1];
		}
	}
	
}